#include <string>
#include <algorithm>
using namespace std;
class Solution {
public:
    string multiply(string num1, string num2) {
        string ret="";
        int g=0;
        for (int sum=num1.size()-1+num2.size()-1;sum>=0;--sum) {
            for (int i=num1.size()-1;i>=0;i--) {
                int j=sum-i;
                if (0<=j && j<num2.size()) g+=(int)(num1[i]-'0')*(int)(num2[j]-'0');
            }
            ret.push_back((char)(g%10+'0'));
            g/=10;
        }
        while (g>0) {
            ret.push_back((char)(g%10+'0'));
            g/=10;
        }
        while (ret.size()>0 && ret.back()=='0') ret.pop_back();
        if (ret.size()==0) ret="0";
        for (int i=0;i<ret.size()/2;i++)
            swap(ret[i], ret[ret.size()-1-i]);
        return ret;
    }
};
